//################################
// 版权所有：中国农业银行软件开发中心
// 系统名称：移动办公应用-手机版
// 文件名称：pandaTextInput.js
// 创建时间：2016年10月14日
// 创建人员：Panda
// 功能说明：带下拉菜单的文本输入框
//################################

'use strict';

import React, {Component} from 'react';
import {
    // TextInput,
    Text,
    ListView,
    TouchableOpacity,
    StyleSheet,
    View,
    Dimensions,
} from 'react-native';

import {
    Colors,
} from '../../common';

import Icon from 'react-native-vector-icons/EvilIcons';
import TextInput from 'react-native-autocomplete-input';

const WINDOW_HEIGHT = Dimensions.get('window').height;

class PandaTextInput extends Component {
    constructor(props) {
        super(props);
        
        this.data = props.data;
        this.defaultValue = this.data.toString();
        this.textInputPlaceHolder = props.placeholder;
    }

    componentWillReceiveProps(nextProps) {
        this.data = nextProps.data;
        this.defaultValue = this.data.toString();
    }
    

    render() {
        // return (
        //     <View style={styles.container}>
        //         <TextInput
        //             ref={(ref) => {this.textInput = ref}}
        //             style={styles.textinput}
        //             autoCapitalize={'none'}
        //             autoCorrect={false}
        //             containerStyle={styles.autocompletecontainer}
        //             inputContainerStyle={styles.inputcontainer}
        //             listStyle={styles.liststyle}
        //             placeholder={this.textInputPlaceHolder}
        //             renderItem={(item) => (
        //                 <View style={styles.item}>
        //                     <Text style={styles.itemtext}>{item}</Text>
        //                     <TouchableOpacity style={styles.deletebutton} onPress={()=>null}>
        //                         <Icon style={styles.deleteicon} name={'minus'} size={28} color={Colors.attachmentIcon} />
        //                     </TouchableOpacity>
        //                 </View>
        //             )}
        //             data={this.data}
        //             returnKeyType={'done'}
        //             onSubmitEditing={(e) => alert('结束输入并确认')}
        //         />
        //     </View>
        // );

        return (
                <TextInput
                    ref={(ref) => {this.textInput = ref}}
                    style={styles.textinput}
                    autoCapitalize={'none'}
                    autoCorrect={false}
                    containerStyle={styles.autocompletecontainer}
                    inputContainerStyle={styles.inputcontainer}
                    listStyle={styles.liststyle}
                    placeholder={this.textInputPlaceHolder}
                    renderItem={(item) => (
                        <View style={styles.item}>
                            <Text style={styles.itemtext}>{item}</Text>
                            <TouchableOpacity style={styles.deletebutton} onPress={()=>null}>
                                <Icon style={styles.deleteicon} name={'minus'} size={28} color={Colors.attachmentIcon} />
                            </TouchableOpacity>
                        </View>
                    )}
                    data={this.data}
                    returnKeyType={'done'}
                    onSubmitEditing={(e) => alert('结束输入并确认')}
                    defaultValue={this.defaultValue}
                />
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    textinput: {
        
    },
    autocompletecontainer: {
        borderWidth: 1,
        borderColor: 'yellow',
    },
    inputcontainer: {
        flex: 1,
        borderWidth: 1,
        borderColor: 'red',
        margin: 0,
    },
    item: {
        flex: 1,
        flexDirection: 'row',
        paddingTop: 8,
        paddingBottom: 8,
        borderBottomWidth: 1,
    },
    liststyle: {
        height: WINDOW_HEIGHT / 2,
    },
    itemtext: {
        flex: 1,
    },
    deletebutton: {
        
    },
    deleteicon: {

    },
});

export default PandaTextInput;